import { message } from 'antd';

import { isSuccess } from '@/utils/request';

import { queryPayrollTableToolMsg } from '@/services/salaryManage/salaryCalculate';

const namespace = 'rejectTabModel';
export default {
    namespace,
    state: {
        labelFlagIsShow: '',
        labelWhichShowFlag: '',
        tableDisplayLabel: ''
    },
    reducers: {
        setInitData(state, action) {
            return {
                ...action.payload
            };
        }
    },
    effects: {
        *initData(state, { put, call }) {
            const response = yield call(queryPayrollTableToolMsg, state.payload);
            if (!isSuccess(response)) {
                yield put({
                    type: 'setInitData',
                    payload: {
                        labelFlagIsShow: '',
                        labelWhichShowFlag: '',
                        tableDisplayLabel: ''
                    }
                });
                message.error(`请求【当前月份】数据失败：${response.msg}`);
            } else {
                const { labelFlagIsShow, labelWhichShowFlag, tableDisplayLabel } = response.data;
                yield put({
                    type: 'setInitData',
                    payload: {
                        labelFlagIsShow,
                        labelWhichShowFlag,
                        tableDisplayLabel
                    }
                });
            }
        },
        *resetData(state, { put }) {
            yield put({
                type: 'setInitData',
                payload: {
                    labelFlagIsShow: '',
                    labelWhichShowFlag: '',
                    tableDisplayLabel: ''
                }
            });
        }
    }
};
